package com.tj.collection.controller.admin.request;


import com.fqgj.common.api.ParamsObject;
import com.fqgj.exception.common.ApiIllegalArgumentException;

import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: sm
 * Date: 2016/11/22
 * Time: 下午7:26
 */
public class AddRoleOperationVo extends ParamsObject {
    private Long roleId;
    private List<String> operationIds;


    public Long getRoleId() {
        return roleId;
    }

    public AddRoleOperationVo setRoleId(Long roleId) {
        this.roleId = roleId;
        return this;
    }

    public List<String> getOperationIds() {
        return operationIds;
    }

    public AddRoleOperationVo setOperationIds(List<String> operationIds) {
        this.operationIds = operationIds;
        return this;
    }

    @Override
    public void validate() {
        if (roleId == null ) {
            throw new ApiIllegalArgumentException("参数错误");
        }

        List<String> ids = new ArrayList<>();
        for (String operationId : operationIds) {
            if (operationId.startsWith("a")) {
                ids.add(operationId.substring(1));
            }
        }

        operationIds = ids;
    }
}
